home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-04-17 | 69.8 KB | 1,843 lines |
- SOLVED EXERCISES IN SIMULATION USING SSS
- ========================================
-
- by M. A. Pollatschek, IE Technion, Haifa 32000 ISRAEL
-
- How to use this file
- ====================
- The exercises below are ordered by their complexity. To fully
- benefit from them proceed to the next exercise when the solutions
- of the previous ones are clear. The actual computer codes for
- exercise x.y are in files EX_0x0y.* (* = BAS, C, FOR, PAS).
- Compare the relevant part of this file with them as well as files
- MANUAL.SSS and GLOSSARY.SSS. Use index in the end with an
- editor's (or lister's or word processor's) search facility to
- quickly locate topics. Editors showing at once up to four files
- are especially helpful. (Can be obtained from author by sending a
- DOS formatted 340K 5.25" diskette in a selfaddressed mailer + $30
- to cover expenses.)
-
- EXERCISE 2.1
- ============
- Problem statement
- -----------------
- Simulate the arrival of ships to a harbor during ten days if
- known that on the average two ships enter the port in one day.
- Assume that the probability of a ship's appearance during any
- second is the same irrespective of the time of the day, the
- date or other ship's arrivals. [Listing 1]
-
- New simulation concept
- ----------------------
- * Simulation of processes evolving in time
-
- New SSS routine
- ---------------
- EX(M) Random exponential variate with mean M, models well
- random interarrival times
-
- Variable
- --------
- pt = present time
-
- Points to observe
- -----------------
- * Two ships per day means that mean interarrival time between
- ships is 1/2 day
- * In SSS you decide upon the time units, but STICK to one unit
- through the model (do not mix days and hours, etc).
-
- Pseudo code
- -----------
- Set present time to first arrival as a random variate (EX(0.5)).
- Loop until present time is less then 10:
- add random interarrival time (EX(0.5)) to present time.
- End of loop.
-
- Tutor SSS Page 2
-
- EXERCISE 2.6
- ============
- Problem statement
- -----------------
- Simulate telephone conversations of a manager during two
- hours. The time between conclusion of a call and the start of
- the next is normally distributed with mean 7 minutes and
- standard deviation 4 minutes. Quarter of the calls are to new
- customers, their length is distributed by the Erlang
- distribution with two stages and average length of 4 minutes.
- The rest of the calls are triangularly distributed between 1
- and 4 minutes and mode 3 minutes. [Listing 2]
-
- New simulation concept
- ----------------------
- Choice in a random manner with given probabilities by calling
- RA()
-
- New SSS routines
- ----------------
- RA() Random number between 0 and 1
- RN(M,S) Random normal variate with mean M and standard
- deviation S
- TR(I,B,C) Random normal deviate from triangular distribution
- with minimum I, maximum C and mode B
-
- Programming tip
- ---------------
- To keep random normal variate non negative call RN() via
- subroutine rnx() which does not let through a negative value
-
- Variable
- --------
- pt = present time
-
- Subroutine
- ----------
- rnx(m, s) returns a normal variate with mean m, standard
- deviation s while the negative part is truncated
-
- Pseudo code of main routine
- ---------------------------
- Set present time to time that first call comes in.
- Loop:
- Advance present time to end of present conversation:
- with probability 1/4 by a random Erlang variate,
- with complimentary probability by a random triangular
- variate.
- Advance present time to start of next call by a (truncated)
- normal variate.
- Loop until present time passes 120.
-
- Tutor SSS Page 3
-
- EXERCISE 2.9
- ============
- Problem statement
- -----------------
- Collect the statistics of all the call lengths in 2.6
- irrespective of their origin and the cycle time.
- Report both on screen and file RESULTS. [Listing 3]
-
- New SSS routines
- ----------------
- INIQUE(0,0,s) Initializes s statistics collection
- INISTA(j,h,0,l,f,w) Initializes j-th statistic collection
- TALLY(j,v) Registers v for statistic j
- SUMRY(u) Prints out standard report
-
- Programming tips
- ----------------
- * Keep most variables global (common in FORTRAN, common
- shared in BASIC).
- * Keep all the initializations (such as call to INIQUE) in
- subroutine prime.
-
- Variables
- ---------
- pt = present time
- pv = time that previous conversation ended
- x = time of conversation
-
- Statistics
- ----------
- 1. for x
- 2. for pt - pv when pt = end of present conversation
-
- Subroutines
- -----------
- prime() Initializes statistics, pt (start of first call) and
- pv.
- rnx(m, s) Returns a normal variate with mean m, standard
- deviation s while the negative part is truncated.
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- Loop:
- Let length of call be x, a random variate taken from
- Erlang distribution with probability 1/4
- triangular distribution with complimentary probability.
- Collect observation x.
- Advance present time, pt, to end of call.
- Collect time from previous end of call (pv) to the present
- one (pt).
- Save pt in pv for next time.
- Advance present time to start of next call by a (truncated)
- normal variate.
- Loop until present time passes 120.
- Print out standard report on screen and file RESULTS.
-
- Tutor SSS Page 4
-
- EXERCISE 3.1
- ============
- Problem statement
- -----------------
- What is the fraction of time in 2.6 that the phone is busy?
- [Listing 4]
-
- New simulation concepts
- -----------------------
- * Stochastic process: a variable having a value at each time
- (such as state of a phone [free=0, busy=1]) where time average
- counts rather than ordinary average.
- * Time persistent statistic: statistic about a stochastic
- process.
-
- New SSS routines
- ----------------
- INISTA(j,h,1,l,f,w) Initializes time persistent statistic
- SETT(g) Sets simulated time to g
- T() Returns simulated time
-
- Programming tips
- ----------------
- * Denote states by constants (in FORTRAN as common variables
- initialized in prime()).
- * Use of SSS subroutines saves variables.
-
- Constants
- ---------
- free (0) State of phone being free
- busy (1) State of phone being busy
-
- Statistic
- ---------
- 1. for free and busy - time persistent
-
- Subroutines
- -----------
- prime() Initializes statistics, arrival of first call,
- registration of phone's states.
- rnx(m, s) Returns a normal variate with mean m, standard
- deviation s while the negative part is truncated.
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- Loop:
- Advance simulated time to end of call by a random variate
- taken from -
- Erlang distribution with probability 1/4
- triangular distribution with complimentary probability.
- Register change of phone's state for utilization statistics
- Advance simulated time to start of next call by a (truncated)
- normal variate.
- Register change of phone's state for utilization statistics.
- Loop until present time passes 120.
- Print standard report.
-
- Tutor SSS Page 5
-
- EXERCISE 3.5
- ============
- Problem statement
- -----------------
- Simulate the inventory of a photo shop concerning a single
- type of camera. There is a customer for the camera every two
- days on the average. The shop gets new cameras every 30 days so
- that it starts a new period of 30 days always with 15 cameras
- on the shelf, no matter how many has been sold. Simulate three
- periods of 30 days to know the number of requests which cannot
- be satisfied and the average stock. [Listing 5]
-
- Subroutine
- -----------
- prime() initializes statistics
-
- Variables
- ---------
- i = index of month, each one having 30 days
- c = stock
-
- Statistics
- ----------
- 1. 1 every time that c = 0 when a customer arrives
- 2. for c - time persistent
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- For each of the 3 months do:
- Start stock (in the beginning of month) at 15.
- Set simulated time to start of month.
- Register stock level to 2nd (time persistent) statistics.
- Advance time to first customer's arrival.
- While still in present month do:
- If there is stock, decrease it-this is selling to customer
- Otherwise (if cannot sell), count case of out of stock
- condition.
- Register stock level to 2nd (time persistent) statistic.
- Advance simulated time to following customer's arrival.
- Print standard report.
-
- Tutor SSS Page 6
-
- EXERCISE 4.3
- ============
- Problem statement
- -----------------
- What is the satisfactory size of a parking lot for a shop if
- known that at peak hours the arrival rate is 30 customers per
- hour and each one spends in the shop 20 minutes on the average.
- Assume that each customer arrives in one car and the cars are
- of approximately the same size. [Listing 7]
-
- New simulation concepts
- -----------------------
- * Entity: a car owner or a similar object which goes through the
- system.
- * Current entity: the entity under consideration. Maximum one
- entity should be current at any given time in the code,
- although conceptually, many parallel activities can be
- simulated.
- * Event: change of state at a certain instant such as another car
- in the parking lot.
- * Calendar: the list of entities whose events should occur in
- some future time. New entities are placed on the calendar by
- subroutine CREATE and current entity by subroutine SCHED.
- * Event code: a positive integer characterizing an event. Each
- event has a distinct event code. Event code 1 is preserved for
- the arrival event.
- * Event loop: "case loop" (or its equivalent in FORTRAN) which is
- driven by the entities in the calendar and function NEXTEV
- which removes the entity from the calendar whose event time is
- closest to present simulated time and makes it current. NEXTEV
- returns the event code of the entity, which is directed to its
- respective label (such as ARRIVL). Event code 0 causes to exit
- the event loop. NEXTEV returns 0 when the calendar is empty or
- time set by SIMEND arrived.
-
- New SSS routines
- ----------------
- CREATE(g,i) Creates an arrival in time g from present time
- with id i
- DISPOS() Destroys current entity if exists
- NEXTEV() Returns event code of following event
- SCHED(g,e,i) Schedules event e>1 for time g from present time
- with id i
- SIMEND(g) Ends simulation at time g (absolute)(g=0: end now)
-
- Programming tips
- ----------------
- * Always put entities in the calendar in the initialization,
- otherwise the program does not enter to event loop.
- * "Hiding" the code of an event or parts of it in a subroutine
- improves readability and ease of maintenance.
- * Dispose the entity as soon as its presence is not necessary.
- * SCHED(0,e,i) acts as "goto" for an entity.
-
- Tutor SSS Page 7
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code of starting an activity (parking and
- buying)
- ENDACT(3) Event code of ending activity (picking up the car
- and leaving)
-
- Variables
- ---------
- c = number of parking cars
- ecode = current value of event code
-
- Statistic
- ---------
- 1. for c - time persistent
-
- Subroutines
- -----------
- prime() Initializes statistics, sets simulation end at 40
- time units, creates the first customer arrival, sets
- initial number of parking cars to 0 and registers it
- for collecting time persistent statistics.
- leavec() Increase the number of parking cars, register it for
- time persistent statistic, schedule time when car is
- picked up as a random time interval from now.
- pickc() Decrease the number of parking cars, register it for
- time persistent statistic. Customer leaves the lot
- (DISPOS).
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- Create next customer's arrival in a random time from now
- (EX(2)) and send customer to park car (STARTA)
- Parking the car (STARTA):
- Perform the code in subroutine leavec().
- Picking up the car (ENDACT):
- Perform the code in subroutine pickc().
- End of event loop.
- Print standard report.
-
- Tutor SSS Page 8
- EXERCISE 4.1
- ============
- Problem statement
- -----------------
- Assume that the reorder policy of the camera shop in 3.5 is
- that every time the stock falls below 4 cameras, an order is
- placed for 12 cameras. Generally 7 days pass until the supply
- is obtained, but deviation of up to 2 days is expected.
- Simulate the shop for 40 days when the starting stock is 15.
- [Listing 6]
-
- New SSS routine
- ---------------
- IDE() Returns identity of current entity
-
- Point to observe
- ----------------
- All the new entities, no matter what they are (e.g. whether
- customers or shipments) introduced to the system at label
- ARRIVL.
-
- Programming tips
- ----------------
- * Counting can be performed by TALLY(j,1) if j is regular (not
- time persistent) statistic.
- * Set distinct identities for each entity type and separate them
- by assigned identity code (last parameter in CREATE & SCHED).
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- TRYBUY(2) Event code that a customer wishes to buy
- REPLNS(3) Event code that a new shipment replenishes stock
- CUSTMR(0) Identity code of a customer
- GOODS (1) Identity code of a new shipment
-
- Variables
- ---------
- c = stock level of cameras
- ecode = current value of event code
-
- Types of entities (identities)
- ------------------------------
- 0: customer
- 1: new shipment
-
- Statistics
- ----------
- 1. 1 every time that c = 0 when a customer arrives, counts
- dissatisfied customers
- 2. for c - time persistent
-
- Tutor SSS Page 9
-
- Subroutines
- -----------
- prime() Initializes statistics, sets simulation end at 40
- time units, creates the first customer arrival, sets
- initial stock to 15 and registers it for collecting
- time persistent statistics.
- buying () If stock reaches level 4, it enters an order for a
- new shipment by creating GOODS arrival a random time
- from now (from the triangular distribution). If there
- is stock, it is decreased by 1 by the purchase. If
- there is no stock it counts (by TALLY) the
- unsatisfied customer. It registers the new stock
- level for the time persistent statistic.
- order () Stock is increased by 12. It registers the new stock
- level for the time persistent statistic.
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- If it is a customer, create next customer's arrival in a
- random time from now (EX(2)) and send the entity to buy.
- If it is not a customer (e.i., it is a shipment) send it to
- replenish the stock.
- Buying by a customer (TRYBUY):
- Perform the code in subroutine buying().
- Replenishing stock (REPLNS):
- Perform the code in subroutine order().
- End of event loop.
- Print standard report.
-
- EXERCISE 4.7
- ============
- Problem statement
- -----------------
- A shop for watch repair is open from 10 am through 10 pm,
- seven days a week. On an average week 25 faulty watches arrive
- for repair and they may came even when the shop is closed. In
- the last situation they are left in the "night" box. It takes 2
- hours to repair a watch on the average. Renewed watches are
- sent back to customers at the end of day (at 10 pm). What
- should be the size of the night box and the shelves dedicated
- for watches waiting for repair and those waiting for delivery?
- Assume that work is continued as usual on a piece which has
- been started before 10 pm no matter what the time is.
- [Listing 8]
-
- Programming tips
- ----------------
- * Different kinds of periods (such as the shop is opened and
- closed) is modelled by an entity whose role is to set an
- appropriate switch (open/close) at given times.
- * Define TRUE/FALSE in BASIC/C for better readability
-
- Tutor SSS Page 10
-
- Points to observe
- -----------------
- * When an event is scheduled, it is always made for the current
- entity. Therefore, when SCHED(g,e,i) is called there MUST BE a
- current entity. After the call that entity survives in the
- calendar and there is no current entity in system. Hence, if
- you SCHEDule another event (such as CLOSES, STARTA, etc) do not
- call DISPOS. However, if you do not SCHEDule another event do
- call DISPOS (as is done in subroutine box(), newday(), etc).
- * When an event has to arrive to ARRIVL event it must be CREATed
- and not SCHEDuled.
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code that a repair activity commences
- ENDACT(3) Event code that repair activity is finished
- NEXTAC(4) Event code where it is decided what to do with the
- current entity
- STRTDY(5) Event code for opening the shop at the STaRT of DaY
- CLOSES(0) Identity code meaning that entity closes the shop
- WATCH(1) Identity code meaning that entity is a watch
- FALSE In case that language does not have FALSE/TRUE
- TRUE (the case in C & BASIC) define them.
-
- Variables
- ---------
- ecode = current value of event code
- opens = true if and only if shop is open
- repars= true if and only if workman is in middle of repair
- n = number of watches in the night box.
- r = number of watches on shelf waiting for repair
- d = number of watches waiting for delivery
- inter = mean interarrival time of watches
- rept = mean repair time
-
- Types of entities (identities)
- ------------------------------
- 0: entity which closes the shop at end of day
- 1: watch
-
- Statistics
- ----------
- 1. for n - time persistent
- 2. for r - time persistent
- 3. for d - time persistent
-
- Subroutines
- -----------
- prime() Initializes statistics, sets simulation end at 10
- time units, creates the first watch arrival and the
- first arrival of closing the shop and initializes
- variables.
-
- Tutor SSS Page 11
-
- clshop() The code for closing shop: clears opens switch (e.i.,
- signalling that shop is closed) and d (e.i. all the
- watches waiting for delivery are taken) and updates
- d's statistic.
- box() The code for leaving a watch in the night box: kill
- the entity by DISPOS, increase the number of watches
- in the night box and register their number for
- statistic #1.
- newday() CREATE an event which closes the shop in another 1/2
- day, kill current event, signal that shop is open
- and that workman is idle, add contents of night box
- (n) to watches waiting for repair (r) and update
- their respective statistics.
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- If it is a watch: CREATE the next watch's arrival at a
- random time from now (EX(inter)) and send entity to NEXT
- ACtivity.
- Otherwise (i.e. it is an entity causing the shop to close):
- SCHEDule opening the shop in another 1/2 day from now and
- perform the code associated with closing the shop
- (clshop()).
- NEXT ACtivity (NEXTAC):
- If shop is open: increase number of watches on shelf
- waiting for repair and register their number for time
- persistent statistic. If worker is repairing, DISPOSe
- entity, otherwise (e.i., worker is free) send entity to
- START of Activity to begin repair.
- Else (e.i., if shop is closed): perform code in subroutine
- box().
- START of Activity (STARTA):
- SCHEDule the finish of repair activity for a random time
- from now (EX(rept)), decrease number watches waiting for
- repair, register their new number in statistic #2, and
- signal that workman is repairing.
- END of ACTivity (ENDACT):
- Increase number of watches waiting for delivery (e.i.,
- after repair but still in shop) and register them in
- statistic #3. If there are more watches waiting for
- repair, start the repairing cycle by sending current
- entity to START of Activiy, otherwise kill current entity
- and set the workman idle (e.i., not repairing).
- STaRT of a new DaY (STRTDY):
- Perform the code in newday().
- End of event loop.
- Print standard report.
-
- Tutor SSS Page 12
-
- EXERCISE 5.1
- ============
- Problem statement
- -----------------
- What is the time that passes between leaving a watch in the
- shop and its delivery in 4.7 ? [Listing 9]
-
- New simulation concepts
- -----------------------
- * Attribute: A numerical characteristic carried by each entity
- such as time of arrival
- * Queue: A buffer where entities are waiting.
-
- New SSS routines
- ----------------
- INIQUE(q,b,s) Initializes q queues, b attributes, s statistics
- SETA(n,v) Sets attribute n of current entity to v
- A(n) Returns the n-th attribute of current entity
- QUEUE(m,0) Enters the current entity to queue m
- REMVFQ(m,r) Removes r-th entity from queue m
- NQ(m) Returns the number of entities in queue m
-
- Programming tips
- ----------------
- * When necessary to empty a queue use the code similar to the
- loop in subroutine clshp()
- * When necessary to move all the entities in a queue to another
- use code similar to the loop in subroutine newday()
-
- Points to observe
- -----------------
- * DISPOSe WATCHs only when they really leave the shop, as
- otherwise their arrival time (carried by them as attribute #1)
- is lost.
- * Incrementing/decrementing of entities in queues is done
- automatically by QUEUE/REMVFQ
- * The time persistent statistic for queue size is automatically
- updated and printed out by SUMRY
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code that a repair activity commences
- ENDACT(3) Event code that repair activity is finished
- NEXTAC(4) Event code where it is decided what to do with the
- current entity
- STRTDY(5) Event code for opening the shop at the STaRT of DaY
- CLOSES(0) Identity code meaning that entity closes the shop
- WATCH(1) Identity code meaning that entity is a watch
- FALSE In case that language does not have FALSE/TRUE
- TRUE (the case in C & BASIC) define them.
-
- Tutor SSS Page 13
-
- Variables
- ---------
- ecode = current value of event code
- opens = true if and only if shop is open
- repars= true if and only if workman is in middle of repair
- inter = mean interarrival time of watches
- rept = mean repair time
-
- Types of entities (identities)
- ------------------------------
- 0: entity which closes the shop at end of day
- 1: watch
-
- Queues
- ------
- 1. Watches in the night box
- 2. Watches waiting for repair in the shop
- 3. Watches waiting for delivery
-
- Attribute
- ---------
- 1. Time of watch's arrival
-
- Statistic
- ---------
- 1. Sojourn time of the watch
-
- Subroutines
- -----------
- prime() Initializes queues, attribute, statistics, sets
- simulation end at 10 time units, creates the first
- watch arrival and the first arrival of closing the
- shop and initializes variables.
- clshop() The code for closing shop: clears opens switch (e.i.,
- signalling that shop is closed) and empties queue #3,
- registering the entity's sojourn times.
- newday() CREATE an event which closes the shop in another 1/2
- day, kill current event (CLOSES), signal that shop is open
- and that workman is idle and move all the contents of
- night box (queue #1) to queue #2.
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- If it is a watch: CREATE the next watch's arrival at a
- random time from now (EX(inter)), mark the arrival time
- in 1st attribute and send entity to NEXT ACtivity.
- Otherwise (i.e. it is an entity causing the shop to close):
- SCHEDule opening the shop in another 1/2 day from now and
- perform the code associated with closing the shop
- (clshop()).
-
- Tutor SSS Page 14
-
- NEXT ACtivity (NEXTAC):
- If shop is open: if workmen is busy put entity (WATCH) to
- queue #2 otherwise (e.i., worker is free) send entity to
- START of Activity to begin repair.
- Otherwise:(e.i., if shop is closed): put entity (WATCH) to
- queue #1.
- START of Activity (STARTA):
- SCHEDule the finish of repair activity for a random time
- from now (EX(rept)) and signal that workman is repairing.
- END of ACTivity (ENDACT):
- Put the entity (WATCH) to queue #3. If there are more
- watches waiting for repair (e.i. queue #2 is not empty)
- remove the first entity (WATCH) from queue #2 and "send"
- it to STARTA, otherwise set the workman idle (e.i., not
- repairing).
- STaRT of a new DaY (STRTDY):
- Perform the code in newday().
- End of event loop.
- Print standard report.
-
- EXERCISE 5.5
- ============
- Problem statement
- -----------------
- A station provides service to customers who arrive randomly
- with an arrival rate of 1 per hour. Each customer requires a
- normally distributed service time the mean of which is 40
- minutes and the standard deviation of which is 10 minutes.
- Customers are reimbursed for the time that they are in the
- system. The payment p is such that (p-1) is exponentially
- distributed with mean of $2 per hour. What is the average
- payment to a customer? [Listing 10]
-
- Programming tip
- ---------------
- Identity code can be a counter of arrived entities, then each
- entity can be tracked by its unique IDE()
-
- Point to observe
- ----------------
- Program is same for any number of identical servers.
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code that a service activity commences
- ENDACT(3) Event code that service activity is finished
- NEXTAC(4) Event code where it is decided what to do with the
- current entity
-
- Variables
- ---------
- id = identity code of previously CREATEd entity (counter)
- server = number of free servers
- ecode = present value of event code
-
- Tutor SSS Page 15
-
- Queue
- -----
- 1. Waiting line in front of the service station
-
- Attribute
- ---------
- 1. Arrival time
-
- Statistics
- ----------
- 1. Cost associated with customer's time in service station
-
- Subroutine
- ----------
- prime() Initializes queue, attribute, statistic, sets
- simulation end at 24 time units, creates the first
- customer arrival and initializes variables.
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- Increase the entity counter and CREATE next entity in EX(1)
- time from now. Note arrival time in attribute #1 and send
- the customer to NEXT ACtivity.
- NEXT ACtivity (NEXTAC):
- If there is a free server send the customer to START
- service Activity, otherwise put customer to waiting line
- (queue #1).
- START of service Activity (STARTA):
- SCHEDule the end of service a random time from now from the
- normal distribution. Decrement the number of free servers.
- END of service ACTivity (ENDACT):
- Register the cost associated with the service, DISPOSe the
- current customer and increase the number of free servers.
- If there is a customer in the waiting line (e.i., if
- NQ(1) is positive), take the first waiting customer and
- START a service Activity.
- End of event loop.
- Print standard report.
-
- Tutor SSS Page 16
-
- EXERCISE 5.6
- ============
- Problem statement
- -----------------
- In a workshop there are three workstations in tandem, the
- first gets the parts from another department and the others get
- them from the previous station. After each station there is a
- quality control station which may reject a defective part for
- rework at the same station (assume it is possible to rework the
- parts in a countless number of times if necessary). The
- probabilities of a defective part are 0.3, 0.2, 0.1 at stations
- # 1, 2, 3 respectively. The time for rework is half of the time
- that the part underwent at the same station before. There are
- finite buffers of 5 parts in front of each station except the
- first. If they are full no more parts can be started in the
- previous station. The arrival of new parts from previous
- department is random with average of 2 parts per hour. The time
- of working at each station is normally distributed with mean of
- 15 minutes and standard deviation of 3 minutes. What is the
- portion of time that the stations make productive work, thus
- neither waiting nor reworking? [Listing 11]
-
- New simulation concept
- ----------------------
- * A station is blocked if it cannot work because the buffers in
- front of it are full.
-
- Programming tips
- ----------------
- * Use identity to mean which station serves the part and how many
- reworks has been done to it. Therefore let identity be
- 4*rewkn + (statn - 1). This is a way to compress information
- when necessary.
- * Identity code may have different meanings at ARRIVL and
- elsewhere because no entity can go back to arrival event once
- it became current.
- * Debug of complex logic can be performed by selective printouts
- at strategic places governed by a debug flag. This can be left
- in the final code (when the debug flag is turned off) to
- facilitate maintenance and code reuse. Note the role of
- subroutine wait().
- * Utilize station indeces to simplify references to queues,
- statistics, etc.
-
- Points to observe
- -----------------
- * A message sent to a label is modelled by an entity carrying the
- contents of massage as identity or attribute.
- * All the event labels serve as a generic model of any station
- when the actual station is dealt through the station indeces.
- * Sending an entity to an event label by SCHED can be performed
- from anywhere, also from a subroutine. Note that SCHED works
- for an entity as a "nonlocal goto" (or "long jump").
-
- Tutor SSS Page 17
-
- * When a station stops being blocked, the "unblocking" action may
- reverberate "upstream". Note how it is done in subroutine
- unblk(i).
- * Although in FORTRAN a subroutine cannot call itself, but two
- can call each other any times, which has the same effect
- (recursion) - this happens with triggr(i) and unblk(i) below.
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code that a service activity commences
- ENDACT(3) Event code that service activity is finished
- NEXTAC(4) Event code where it is decided what to do with the
- current entity
- FINAL(3) Index of final station
- FALSE In case that language does not have FALSE/TRUE
- TRUE (the case in C & BASIC) define them.
-
- Variables
- ---------
- ecode = present value of event code
- statn = present index of station
- rewkn = rework counter at station statn (0 for first
- processing at statn)
- debugf = debug flag
- serial = serial number of parts
- busy[i] = TRUE if station i is busy (working on a part)
- block[i] = TRUE if station i is blocked
- defect[i]= probability of founding a defective part after
- station i.
-
- Types of entities (identities)
- ------------------------------
- At ARRIVL event:
- 0: part
- i: massage that station i became unblocked
- Elsewhere:
- 4*rewkn + (statn - 1): state of the part - rewkn times has
- been reworked at station number statn.
-
- Queues
- ------
- i. Buffer in front of station i, i=1,2,3
-
- Attributes
- ----------
- 1. working time
- 2. serial number
-
- Statistics
- ----------
- i. Proportion of useful working (working and neither reworking
- or idle) of station i, i=1,2,3
-
- Tutor SSS Page 18
-
- Subroutines
- -----------
- prime() Initializes queue, attribute, statistic, sets
- simulation end at 6 time units, creates the first
- part arrival and initializes variables.
- deciph(i) Decodes identity code (given as argument i) and
- recovers statn and rewkn.
- triggr(i) Triggers start of work for first part waiting in
- buffer in front of station #i by removing the first
- entity from queue #1 and sending it to NEXT Activity.
- It also CREATEs a new entity (massage) that station
- #(i - 1) may be stop being blocked if i > 1.
- unblk(i) Code called every time that station #i may stop being
- blocked. It DISPOSes the entity (massage) and if #i
- indeed has been blocked and can start working on a
- waiting part in its buffer (queue #i is not empty and
- the station is not busy) it starts working by calling
- triggr(i). It also sets its state as being not
- blocked.
- wait() Stops momentarily the running to enable to inspect
- the output.
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- If the new entity is a message that station IDE stopped
- being blocked perform the code of subroutine unblk().
- else (the new entity is a part from another department):
- CREATE the arrival of next new part, set attributes and
- send the part to NEXT Activity.
- NEXT Activity (NEXTA):
- Recover station and rework numbers (by deciph(IDE)).
- If station is busy or blocked then place part to the
- buffer,
- else (neither busy nor blocked) send the part to START of
- Activity event.
- START of Activity (STARTA):
- Recover station and rework numbers (by deciph(IDE)).
- If this part is new for this station (rewkn = 0) register
- it with statistic #statn.
- Set station's state busy and SCHEDule and END of ACTivity
- after processing time (kept in attribute #1).
-
- Tutor SSS Page 19
-
- END of ACTivity (ENDACT):
- Recover station and rework numbers (by deciph(IDE)).
- Register that working is over at statistic #statn.
- Set station's state not busy.
- If part is not defective (which is random: if RA >
- defect(statn)) then:
- If this is the FINAL station, DISPOSe the part,
- else set working time (random normal) for following
- station in attribute #1 and send it to NEXT Activity.
- Otherwise (if part is defective): set its new working time
- as half of its last time (all is kept in attribute #1)
- and SCHEDule it for a rework while noting in the identity
- the updated rework number.
- If there are more parts waiting for this station perform
- the code in subroutine triggr for this station.
- End of event loop.
- Print standard report.
-
- EXERCISE 6.1
- ============
- Problem statement
- -----------------
- What is the average payment in 5.5 if the queue is ranked by
- the ratio (hourly payment)/(service time) ? [Listing 12]
-
- New simulation concept
- ----------------------
- Queue discipline: a rule determining the ordering of entities
- in the queue. May be one of: FIFO (first in first out -
- default), LIFO (last in first out), BVF (big value first - ties
- are broken by FIFO), SVF (small value first - ties are broken
- by LIFO).
-
- New SSS routines
- ----------------
- SETQDC(m,d) Sets discipline d in queue number #m
- QUEUE(m,p) Enters current entity to queue m with priority p
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code that a service activity commences
- ENDACT(3) Event code that service activity is finished
- NEXTAC(4) Event code where it is decided what to do with the
- current entity
-
- Variables
- ---------
- id = identity code of previously CREATEd entity (counter)
- server = number of free servers
- ecode = present value of event code
-
- Tutor SSS Page 20
-
- Queue
- -----
- 1. Waiting line in front of the service station
-
- Attributes
- ----------
- 1. Arrival time
- 2. Hourly payment
- 3. Service time
-
- Statistic
- ---------
- 1. Cost associated with customer's time in service station
-
- Subroutine
- ----------
- prime() Initializes queue, attribute, statistic, sets
- simulation end at 24 time units, creates the first
- customer arrival, initializes variables and sets
- queue discipline to SVF.
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- Increase the entity counter and CREATE next entity in EX(1)
- time from now. Set all three attributes and send the
- customer to NEXT ACtivity.
- NEXT ACtivity (NEXTAC):
- If there is a free server send the customer to START
- service Activity, otherwise put customer to waiting line
- (queue #1) with priority which is the quotient
- (hourly payment)/(service time).
- START of service Activity (STARTA):
- SCHEDule the end of service a random time from now from the
- normal distribution. Decrement the number of free servers.
- END of service ACTivity (ENDACT):
- Register the cost associated with the service, DISPOSe the
- current customer and increase the number of free servers.
- If there is a customer in the waiting line (e.i.,
- if NQ(1) is positive), take the first waiting customer
- and START a service Activity.
- End of event loop.
- Print standard report.
-
- Tutor SSS Page 21
-
- EXERCISE 6.4
- ============
- Problem statement
- -----------------
- In a repair shop there are two servers, both of whose service
- times are triangularly distributed with parameters 1,2,3 in
- hours. Customers may chose between ordinary and deluxe service,
- while the last one means that they are immediately served even
- if a server is busy with an ordinary customer. In the latter
- case the ordinary customer will wait and will be served
- immediately after all deluxe customers and his new service time
- will be whatever is left from his previous services. There is a
- single queue for ordinary customers who go to the first server
- who is free even if this means that he gets service from two
- different servers. Assume that customers arrive every two hours
- on the average and quarter of them chooses the deluxe service.
- How many interrupts will experience an average ordinary
- customer? [Listing 13]
-
- New simulation concepts
- -----------------------
- * Preemptive priority: when entity preempts the resource (server)
- from entity of lower priority.
- * Residual time: the time left from moment of preempting until
- end of service
- * Rank: the place of entity in calendar or queue.
-
- New SSS routines
- ----------------
- NC() Returns the number of scheduled items in calendar
- AIC(r,n) Returns r-th entity's n-th attribute in calendar
- NEIC(r) Returns the event code of r-th entity in calendar
- TIC(r) Returns r-th enitity's time in calendar
- REMVFC(r) Removes r-th entity from calendar
-
- Programming tips
- ----------------
- * To find an entity whose service is under way go over the
- calendar and try to find it there according to its event code
- (ENDACT) and its identity and/or attribute(s) - see preemp().
- * To perform the above easier sometimes it is worthwhile to test
- the opposite condition.
- * To place an entity at an arbitrary place in a queue (such as
- placing to first position in a FIFO queue) change queue
- discipline temporarily (to LIFO).
- * Save the relevant parameter of the entity before removing it
- from calendar/queue
-
- Point to observe
- ----------------
- Physically one waiting line is represented by two queues if it
- makes easier to keep apart two kinds of entities (customers).
-
- Tutor SSS Page 22
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code that a service activity commences
- ENDACT(3) Event code that service activity is finished
- NEXTAC(4) Event code where it is decided what to do with the
- current entity
- ORDNRY(0) Identity code for an ordinary customer
- DELUX(1) Identity code for a deluxe customer
-
- Variables
- ---------
- id = identity code of previously CREATEd entity (counter)
- server = number of free servers
- ecode = present value of event code
- remt = residual time (should be saved prior to REMVFC!)
-
- Queues
- ------
- 1. for ordinary customers
- 2. for deluxe customers
-
- Attributes
- ----------
- 1. number of times that an ordinary customer is interrupted in
- middle of service.
- 2. (remaining)service time
- 3. type: deluxe(1)/ordinary(0)
-
- Statistic
- ---------
- 1. Interrupts in middle of service for ordinary customers A(1)
-
- Subroutines
- -----------
- prime() Initializes queue, attribute, statistic, sets
- simulation end at 60 time units, creates the first
- customer arrival and initializes variables.
- preemp() Current entity tries to preempt an ORDiNaRY entity,
- whose rank in calendar is i. If such entity is found
- then it is placed to QUEUE(1) with its remaining
- service time, remt, in A(2) and current one STARTs
- Activity of being served. Otherwise current entity is
- placed to QUEUE(2).
-
- Pseudo code of preemp()
- -----------------------
- Place present entity (must be of deluxe type) to queue #2.
- Go over all entities in calendar with event codes ENDACT and
- try to find an ORDNRY customer. Let its rank be i if found
- while i = NC + 1 if not found.
- If found (i <= NC) then:
- note the residual time in remt, remove it from calendar,
- update its two first attributes, place it as first in queue
- #1, remove the waiting deluxe customer from queue #2 and
- send to START of Activity.
-
- Tutor SSS Page 23
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- Increase the entity counter, CREATE next entity in EX(2)
- time from now, set all the three attributes and send the
- customer to NEXT ACtivity.
- NEXT ACtivity (NEXTAC):
- If there is an available server (server > 0) send entity
- (customer) to START Activity.
- If all the servers are busy and the current customer is of
- deluxe type attempt a preempting in subroutine preemp(),
- otherwise (e.i., if type is ordinary) place customer to
- queue #1.
- START of service Activity (STARTA):
- SCHEDule the end of service A(2) time from now. Decrement
- the number of free servers.
- END of service ACTivity (ENDACT):
- Register the number of interruptions for an ordinary
- customer, DISPOSe the current customer and increase the
- number of free servers. If there is a waiting deluxe
- customer (e.i., if NQ(2) is positive), take the first
- waiting customer and START a service Activity.
- Otherwise, if there is a waiting ordinary customer (e.i.,
- if NQ(1) is positive), take the first waiting customer
- and START a service Activity.
- End of event loop.
- Print standard report.
-
- EXERCISE 7.1
- ============
- Problem statement
- -----------------
- Assume that in problem 6.4 there are two different queues in
- front of the servers and each customer has to decide to which
- waiting line to join. Once in the queue, no customer may change
- mind. The customer joins the line with fewer people and if an
- ordinary customer is preempted he or she should return to the
- same server that they started with. Assume that deluxe
- customers cannot differentiate between ordinary and deluxe
- types, and the queue length seems to them accordingly, if they
- cannot be served. [Listing 14]
-
- New SSS routines
- ----------------
- IDIC(r) Returns the id of r-th entity in calendar
- SETIDE(i) Sets identity of current entity to i
-
- Programming tip
- ---------------
- Make queue and/or resource index function of identity code
- and/or attribute(s), if necessary through functions - see
- shortr() and sindex().
-
- Tutor SSS Page 24
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code that a service activity commences
- ENDACT(3) Event code that service activity is finished
- NEXTAC(4) Event code where it is decided what to do with the
- current entity
- ORD1(1) Identity code for an ordinary customer in first line
- ORD2(2) Identity code for an ordinary customer in second line
- DELUX1(3) Identity code for a deluxe customer in first line
- DELUX2(4) Identity code for a deluxe customer in second line
-
- Variables
- ---------
- server[i] = number of free servers for line #i
- ecode = present value of event code
- remt = residual time (should be saved prior to REMVFC!)
- preide = identity of interrupted customer (ditto to QUEUE!)
-
- Types of entities (identities)
- ------------------------------
- 1. ordinary customer in first line
- 2. ordinary customer in second line
- 3. deluxe customer in first line
- 4. deluxe customer in second line
-
- Queues
- ------
- 1. ordinary customer in first line
- 2. ordinary customer in second line
- 3. deluxe customer in first line
- 4. deluxe customer in second line
- 5. temporary place for deluxe
-
- Attributes
- ----------
- 1. number of times that an ordinary customer is interrupted in
- middle of service.
- 2. (remaining)service time
-
- Statistic
- ---------
- 1. Interrupts in middle of service for ordinary customers A(1)
-
- Subroutines
- -----------
- prime() Initializes queue, attribute, statistic, sets
- simulation end at 60 time units, creates the first
- customer arrival and initializes variables.
- sindex() Returns the server index according to IDE.
- shortr() For an ordinary entity returns 1 or 2, while for a
- deluxe entity returns 3 or 4, depending where the
- queue is shorter. IDE is also updated with the
- returned value.
-
- Tutor SSS Page 25
-
- preemp() Current entity tries to preempt an ORDiNaRY entity,
- whose rank in calendar is i. If such entity is found
- then it is placed to QUEUE(IDE) with its remaining
- service time, remt, in A(2) and current one STARTs
- Activity of being served. Otherwise current entity is
- placed to QUEUE(shortr) - a revised form of
- subroutine preemp() from 6.4
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- CREATE next entity in EX(2) time from now, set all the
- both attributes and send the customer to NEXT ACtivity.
- NEXT ACtivity (NEXTAC):
- If there is an available server (server(i) > 0) send entity
- (customer) to START Activity with appropriate identity.
- If all the servers are busy and the current customer is of
- deluxe type attempt a preempting in subroutine preemp(),
- otherwise (e.i., if type is ordinary) place customer to
- shorter queue appropriate to the identity.
- START of service Activity (STARTA):
- SCHEDule the end of service A(2) time from now. Decrement
- the number of free servers.
- END of service ACTivity (ENDACT):
- Register the number of interruptions for an ordinary
- customer, DISPOSe the current customer and increase the
- number of free servers. If there is a waiting deluxe
- customer (e.i., if NQ(s + 2) is positive), take the first
- waiting customer and START a service Activity. Otherwise,
- if there is a waiting ordinary customer (e.i., if NQ(s)
- is positive), take the first waiting customer and START
- a service Activity.
- End of event loop.
- Print standard report.
-
- EXERCISE 7.2
- ============
- Problem statement
- -----------------
- In a station boxes are assembled from the main part and the
- cover, both has to be of the same color. There are four colors:
- white (35%), blue (15%), red (30%) and yellow (20%). The two
- parts arrive from two different departments at random at the
- rate of 5 parts per hour. The assembly takes a normally
- distributed time with mean of 10 minutes and standard deviation
- of 2 minutes. What should be the buffer sizes of the two parts?
- [Listing 15]
-
- New simulation concept
- ----------------------
- Matching: finding two or more entities in one or more queues
- according to same or opposing identity and/or attribute(s).
-
- Tutor SSS Page 26
-
- New SSS routines
- ----------------
- AIQ(m,r,n) Returns the r-th entity's n-th attribute in queue m
- NCEN() Returns the number of current entities ( 1 or 0)
-
- Programming tip
- ---------------
- Trigger a matching by creating a special entity whose sole
- purpose is attempting to find a match. The triggering is caused
- by finishing working on the previous pair.
-
- Point to observe
- ----------------
- Having found a matching entity to a given one, one must be
- DISPOSed, while the other can represent both (this works well
- only if the pair is not split later)
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code that a service activity commences
- ENDACT(3) Event code that service activity is finished
- NEXTAC(4) Event code where it is decided what to do with the
- current entity
- MATCH(5) Event code that a matching main+cover in same color
- is sought.
- WHITE(1), BLUE(2), RED(3), YELLOW(4) Color values
- MAINP(1) Identity code of main part
- COVER(2) Identity code of cover
- MREQ(3) Identity code of a matching request
-
- Variables
- ---------
- server = number of free servers
- ecode = present value of event code
-
- Types of entities (identities)
- ------------------------------
- 1. main part
- 2. cover
- 3. matching request
-
- Queues
- ------
- 1. for main parts
- 2. for covers
-
- Attributes
- ----------
- 1. color code
-
- Tutor SSS Page 27
-
- Subroutines
- -----------
- prime() Initializes queue, sets simulation end at 120 time
- units, creates the first arrivals for both parts and
- initializes free servers.
- find1() At entry there is a current entity. It attempts to
- find an entity from the other queue with the same
- color. If attempt is successful, the present entity
- is DISPOSed and the matching entity becomes the
- present entity. Otherwise the entity on entry is
- placed in queue and at exit there is no current
- entity.
- find2() At entry there is no current entity. It attempts to
- find two entities with same color from both queues.
- If attempt is successful, one is DISPOSed, the other
- becomes the current entity. Otherwise at exit there
- is no current entity.
- other() Returns the identity of the "other part", e.i., for
- IDE = MAINP it returns COVER and vice versa.
-
- Pseudo code of find1()
- ----------------------
- Go over the "other" queue (e.i., if current entity is MAINP, go
- over queue of COVER and vice versa) and attempt to find there
- an entity with same color (same value of A(1)).
- If found (i <= queue length of "other" queue) DISPOSe current
- entity (as the "other" will represent it), remove the other
- entity from its queue and send it to START of Activity,
- otherwise (e.i., if none is found) place present entity on its
- queue.
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- If this is a matching request go to MATCH label,
- otherwise (it is either a main part or cover) CREATE the
- next arrival in EX(12) time from now, set the color code
- and send entity to NEXT ACtivity.
- NEXT ACtivity (NEXTAC):
- If a server is free and the "other" part's queue is not
- empty send the entity to MATCH,
- else place it to its queue.
- MATCHing two parts(MATCH) :
- If a request came because server became free (IDE = MREQ)
- then DISPOSe current entity (request) and try to find two
- matching parts from the queues (find2()),
- else (matching is to do for a new part which just has
- arrived) try to match another part to current entity
- (find1()).
- If matching is successful (there is a current entity:
- NCEN() > 0) send present entity to START of Activity.
-
- Tutor SSS Page 28
-
- START of Activity (STARTA):
- SCHEDule the END of ACTivity a normally distributed random
- time from now. Decrement the number of free servers.
- END of service ACTivity (ENDACT):
- DISPOSe the current part and increase the number of free
- servers. If there are parts in both queues request a
- MATCHing by CREATE.
- End of event loop.
- Print standard report.
-
- EXERCISE 8.4
- ============
- Problem statement
- -----------------
- Change the service time in problem 5.5 to 54 minutes instead
- of 40. Assume that the station works nonstop and starts with an
- empty queue. What is the length of the warm-up period, or what
- is called the transient period? Use the queue size and its
- standard deviation as criteria. [Listing 16]
-
- New simulation concept
- ----------------------
- Transient period is the time for "warm up" from a "cold start".
- It may be estimated by inspecting a statistic (such as average
- queue size) over time (graphically, using a spreadsheet). Take
- it as the time from simulation start until that the statistic's
- value does not change appreciably
-
- New SSS routines
- ----------------
- QAVG(m) Returns average of queue # m
- QSTD(m) Returns standard deviation of queue # m
-
- Points to observe
- -----------------
- Output is to be processed by a spreadsheet program. Establish
- connection by writing a text file.
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code that a service activity commences
- ENDACT(3) Event code that service activity is finished
- NEXTAC(4) Event code where it is decided what to do with the
- current entity
- TIMEL(150) Time limit on simulation
-
- Variables
- ---------
- n = serial number of entities
- server = number of free servers
- ecode = present value of event code
-
- Tutor SSS Page 29
-
- Queue
- -----
- 1. Waiting line in front of the service station
-
- Subroutine
- ----------
- prime() Initializes queue, sets simulation end at TIMEL time
- units, creates the first customer arrival,
- initializes variables and opens output file.
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- Increase the entity counter and CREATE next entity in EX(1)
- time from now. Send the customer to NEXT ACtivity.
- NEXT ACtivity (NEXTAC):
- If there is a free server send the customer to START
- service Activity,
- otherwise put customer to waiting line (queue #1) and print
- to both screen and text file current value, average and
- standard deviation of queue size.
- START of service Activity (STARTA):
- SCHEDule the end of service a random time from now from the
- exponential distribution. Decrement the number of free
- servers.
- END of service ACTivity (ENDACT):
- DISPOSe the current customer and increase the number of
- free servers. If there is a customer in the waiting line
- (e.i., if NQ(1) is positive), take the first waiting
- customer, START a service Activity and print to both
- screen and text file current value, average and standard
- deviation of queue size.
- End of event loop.
-
- Tutor SSS Page 30
-
- EXERCISE 8.5
- ============
- Problem statement
- -----------------
- Run four replicas of problem 8.4 for sufficient length and
- estimate the expected mean queue size from the results.
- [Listing 17]
-
- New simulation concepts
- -----------------------
- * Run: simulation of a certain length. It refers to either the
- transient period or a sample. Runs may be subsequent and only
- technically separated.
- * Cutting out transient period. To save runs take one transient
- period (call it run 0 - 120 time units) and SSIZE (= sample
- size = 4) consecutive runs not stopping simulations but only
- printing results and clearing statistics.
- * Independent statistics can be obtained from runs of adequate
- length - take below as the transient period (TIMEL = 120).
- * Control statistic technique. Estimate also a quantity that can
- be predicted theoretically (such as free fraction of server,
- 0.9 in this exercise). Regression of statistic in question
- (queue) on size can reduce confidence interval.
-
- New SSS routines
- ----------------
- CLEARQ(m) Clears queue statistic of queue m, if m=0 clears all
- CLEARS(j) Clears statistic # j, if j=0 clears all j
- SAVG(j) Returns average of variable # j
-
- Programming tips
- ----------------
- * Always give signal from program that it works and is well
- especially for long simulations, but without messing the screen
- unnecessarily - see signal or print T;:locate,1 in BASIC
- * To perform the above in a compiler not having subroutines for
- managing the screen (such as FORTRAN) use DOS' ANSI.SYS (take
- care to include it in file CONFIG.SYS)
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code that a service activity commences
- ENDACT(3) Event code that service activity is finished
- NEXTAC(4) Event code where it is decided what to do with the
- current entity
- REPORT(5) Event code of reporting
- REPTME(-1) Identity code of a reporting event
- TIMEL(120) Length of each run
- SSIZE(4) Sample size (number of runs except the warmup)
-
- Tutor SSS Page 31
-
- Variables
- ---------
- n = entity counter
- countr = run's counter
- server = number of free servers
- ecode = present value of event code
-
- Types of entities (identities)
- ------------------------------
- -1 entity at end of transient period and each of the SSIZE
- runs
- n ( >= 0 ) customer
-
- Queue
- -----
- 1. Waiting line in front of the service station
-
- Attribute
- ---------
- 1. Service time
-
- Statistic
- ---------
- 1. Free fraction of server - time persistent
-
- Subroutines
- -----------
- signal() Writes massage always at the same place on screen.
- prime() Initializes queue, sets simulation end at TIMEL time
- units, creates the first customer arrival and
- initializes variables.
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- If entity is end of a run (REPTIME) send it to REPORT event,
- otherwise increase the entity counter, set random service
- time from exponential distribution in attribute #1 and
- CREATE next entity in EX(1) time from now. Write state of
- simulation on screen and send the customer to NEXT
- ACtivity.
- NEXT ACtivity (NEXTAC):
- If there is a free server send the customer to START
- service Activity,
- otherwise put customer to waiting line (queue #1).
- START of service Activity (STARTA):
- SCHEDule the end of service A(1) time from now from the
- exponential distribution. Decrement the number of free
- servers.
-
- Tutor SSS Page 32
-
- END of service ACTivity (ENDACT):
- DISPOSe the current customer and increase the number of
- free servers. If there is a customer in the waiting line
- (e.i., if NQ(1) is positive), take the first waiting
- customer and START a service Activity.
- REPORT:
- SCHEDule next REPORTing in time TIMEL from now, print for
- each sample (except for transient period) average queue
- length and free fraction of server, clear statistics,
- advance run counter. At end of final (SSIZE) run finish
- simulation.
- End of event loop.
-
- EXERCISE 8.7
- ============
- Problem statement
- -----------------
- Try to reduce the variance for problem 8.5 by means of
- antithetic variables. [Listing 18]
-
- New simulation concepts
- -----------------------
- * Random stream: the sequence of random variates denoted as X<1>,
- X<2>,...
- * Seed: the first number of the stream, X<1>. Given X<1>, the
- whole stream is fixed a sequence (e.i., not really random, only
- appears as random, called pseudo random).
- * Antithetic variable: X and Y are antithetic for a probability
- distribution with cumulative function F if F(X) = 1 - F(Y).
- Rerun of the same program with an antithetic stream reduces the
- estimates' variances.
-
- New SSS routines
- ----------------
- SETANT(y) Sets (y > 0)/clears (y = 0) antithetic variables
- SETSEE(x) Sets seed to value x (x is odd positive integer)
-
- Programming tip
- ---------------
- Use SIMEND(0) and an entity counter to stop simulation after a
- given number of customers.
-
- Points to observe
- -----------------
- * Care should be exercised that the two streams should be "in
- phase" EXACTLY (e.i., if X<m> is the the interarrival time
- between customers no. i and i+1, then Y<m> should have the SAME
- significance).
- * To satisfy the above a run will consists of a fixed number of
- customers rather than simulated time and service time is
- determined at arrival (which occurs for both stream at the
- same sequence) rather than at start of service (which is a
- function of the specific stream!). Because of this A(1) is
- needed to hold service time until service actually starts.
-
- Tutor SSS Page 33
-
- Constants
- ---------
- ARRIVL(1) Event code of new arrival to the system
- STARTA(2) Event code that a service activity commences
- ENDACT(3) Event code that service activity is finished
- NEXTAC(4) Event code where it is decided what to do with the
- current entity
- TIMEL(120) Number of customers per run
-
- Variables
- ---------
- n = entity counter
- countr = counter of runs (0 = first run)
- server = number of free servers
- ecode = present value of event code
- t0 = simulated time that present run started
-
- Queue
- -----
- 1. Waiting line in front of the service station
- 2. "Shelter" for an entity to save it from erasing by resque().
- The entity is essential to restart simulation (which is
- generally performed by CREATE inside prime()).
-
- Attribute
- ---------
- 1. Service time
-
- Statistic
- ---------
- 1. Free fraction of server - time persistent
-
- Subroutines
- -----------
- signal() Writes massage always at the same place on screen.
- prime() Initializes queue, sets simulation end at TIMEL time
- units, creates the first customer arrival and
- initializes variables.
- resque() Resets the system: clears all statistics and queues
- except the queue(s) holding entity(ies) which restarts
- simulation.
- endper() Called at beginning/end of each run. Except for end
- of transient periods it prints statistics. In the
- beginning of transient periods it initializes random
- stream by calling SETSEE & SETANT and resets server
- and simulation by calling resque(). In any event it
- clears statistics, advances run counter and saves
- simulated time of run start in t0.
-
- Tutor SSS Page 34
-
- Pseudo code of main routine
- ---------------------------
- Initialize.
- The event loop:
- A new entity arrives (ARRIVL):
- If current entity is the last in this run call subroutine
- endper().
- Increase the entity counter, set random service time from
- exponential distribution in attribute #1 and CREATE next
- entity in EX(1) time from now. Write state of simulation
- on screen and send the customer to NEXT ACtivity.
- NEXT ACtivity (NEXTAC):
- If there is a free server send the customer to START
- service Activity,
- otherwise put customer to waiting line (queue #1).
- START of service Activity (STARTA):
- SCHEDule the end of service A(1) time from now from the
- exponential distribution. Decrement the number of free
- servers.
- END of service ACTivity (ENDACT):
- DISPOSe the current customer and increase the number of
- free servers. Register free servers for statistic #1. If
- there is a customer in the waiting line (e.i., if NQ(1)
- is positive), take the first waiting customer and START
- a service Activity.
- End of event loop.
-
- Tutor SSS Page 35
-
- INDEX OF TUTOR
- ==============
-
- The number x.y refers to the exercise number
-
- A ... ... ... ... ... 5.1 NQ .. ... ... ... ... 5.1
- AIC . ... ... ... ... 6.4 periodic events ... ... 4.7
- AIQ . ... ... ... ... 7.2 preemptive priority ... 6.4
- antithetic variables ... 8.7 priority . ... ... ... 6.1
- ANSI.SYS . ... ... ... 8.5 QAVG ... ... ... ... 8.4
- attribute ... ... ... 5.1 QSTD ... ... ... ... 8.4
- blocked stations ... ... 5.6 QUEUE ... ... ... 5.1,6.1
- calendar . ... ... ... 4.3 RA .. ... ... ... ... 2.6
- CLEARQ ... ... ... ... 8.5 rank ... ... ... ... 6.4
- CLEARS ... ... ... ... 8.5 recursion ... ... ... 5.6
- control statistic .. ... 8.5 REMVFC ... ... ... ... 6.4
- CREATE ... ... ... ... 4.3 REMVFQ ... ... ... ... 5.1
- current entity ... ... 4.3 RN .. ... ... ... ... 2.6
- cycle time ... ... ... 2.9 run . ... ... ... ... 8.5
- debug ... ... ... ... 5.6 SAVG ... ... ... ... 8.5
- discipline ... ... ... 6.1 SCHED ... ... ... ... 4.3
- DISPOS ... ... ... ... 4.3 seed ... ... ... ... 8.7
- entity ... ... ... ... 4.3 SETA ... ... ... ... 5.1
- event ... ... ... ... 4.3 SETANT ... ... ... ... 8.7
- event code ... ... ... 4.3 SETIDE ... ... ... ... 7.1
- event loop ... ... ... 4.3 SETQDC ... ... ... ... 6.1
- EX .. ... ... ... ... 2.1 SETSEE ... ... ... ... 8.7
- goto for an entity . 4.3,5.6 SETT ... ... ... ... 3.1
- IDE . ... ... ... ... 4.1 SIMEND ... ... ... ... 4.3
- IDIC ... ... ... ... 7.1 sojourn time .. ... ... 5.1
- identity of an entity ... 4.1 stochastic process . ... 3.1
- independence .. ... ... 8.5 stream ... ... ... ... 8.7
- INIQUE ... ... ... 2.9,5.1 SUMRY ... ... ... ... 2.9
- initialization ... ... 2.9 T ... ... ... ... ... 3.1
- INISTA ... ... ... 2.9,3.1 TALLY ... ... ... ... 2.9
- interarrival time .. ... 2.1 TIC . ... ... ... ... 6.4
- masseges . ... ... ... 5.6 time persistent statistic 3.1
- matching . ... ... ... 7.2 time unit ... ... ... 2.1
- NC .. ... ... ... ... 6.4 TR .. ... ... ... ... 2.6
- NCEN ... ... ... ... 7.2 transient period ... ... 8.4
- NEIC ... ... ... ... 6.4 work station .. ... ... 5.6
- NEXTEV ... ... ... ... 4.3
-